﻿using System.Collections;

namespace CRMWeb.Utilities.Context
{
    public abstract class AbstractStockHelper<HelperType> where HelperType : AbstractStockHelper<HelperType>, new()
    {
        protected static HelperType Instance = System.Activator.CreateInstance<HelperType>();

        public abstract IDictionary CurrentItems
        {
            get;
        }

        public static object GetItem(string key)
        {
            return GetItem(key, false);
        }

        public static object GetItem(string key, bool caseSensitive)
        {
            //return ItemsFunctions.GetItem(AbstractStockHelper<HelperType>.Instance.CurrentItems, key, caseSensitive);
            var items = Instance.CurrentItems;

            if (items == null || key == null)
            {
                return null;
            }
            if (!caseSensitive)
            {
                //key = key.ToLowerCSafe();
                key = key.ToLower();
            }
            return items[key];
        }

        public static void Add(string key, object value)
        {
            Add(key, value, false);
        }

        public static void Add(string key, object value, bool caseSensitive)
        {
            //ItemsFunctions.Add(AbstractStockHelper<HelperType>.Instance.CurrentItems, key, value, caseSensitive);
            var items = Instance.CurrentItems;
            if (key == null)
            {
                return;
            }
            if (items != null)
            {
                if (!caseSensitive)
                {
                    //key = key.ToLowerCSafe();
                    key = key.ToLower();
                }
                items[key] = value;
            }
        }
    }
}